﻿/// ---------------------------------------------
///
/// ---------------------------------------------

///---------------------------
///2012.4.30 汪定新添加
//双击事件
function CustomDbClick() {
    parent.closeWin(); //去掉双击功能
}
///--------------------
//获取url里的参数值 name:参数名称
function getPar(source, name) {
    var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
    if (reg.test(source))
        return RegExp.$2;
    return "";
};
function getPar1(name) {
    var _url = "http://" + document.location;
    return getPar(_url, name);
}

//添加信息
var fnCustomAdd = function () {
    var deptId = _key;
    if (deptId == null || deptId == "") {
        alert("请选择部门！");
        return;
    }
    const_EditEntity = "hrEmployee";
    var deptName = _Caption;
    var pagetitle = "新增在职员工信息";
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&deptId=" + deptId + "&deptName=" + deptName + "&type=5"));
    parent.NeedRefreshPage = this;
}

var fnCustomReport = function () {
    parent.addTabs("人事报表", ("Extend/ReportView.aspx?entity=V_hrEmployee&order=DeptPath&condition=" + const_Condition + "&customCondition=" + const_CustomCondition));
}

//修改信息
var fnCustomEdit = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    const_EditEntity = "hrEmployee";
    var deptId = _key;
    var deptName = record.getData("DeptName");
    var postName = record.getData("PostName");
    var pagetitle = "修改在职员工信息—" + record.getData("CName");
    parent._employeeTitle = pagetitle;
   
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&id=" + record.getData(const_entityID) + "&deptId=" + deptId + "&deptName=" + deptName + "&postName=" + postName + "&type=1"));
    parent.NeedRefreshPage = this;
}


//查看员工详细信息
var fnChaKanXinXi = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    var id = record.getData(const_entityID);
    var pagetitle = "查看员工信息—" + record._oData["CName"];
    parent.addTabs(pagetitle, "../EHR/hrViewEmployeeInfo.aspx?id=" + id);
    parent.NeedRefreshPage = this;
}



//培训经历
var fnPeiXun = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    var id = record.getData(const_entityID);
    var pagetitle = "培训经历—" + record._oData["CName"];
    parent.addTabs(pagetitle, "../Extend/YUIDataTableList.aspx?id=" + id + "&isShonwBtn=N&functionid=0C9FAF7B-7744-4566-954D-9D5D3C9E866A&entity=hrEmployeeTrainings&condition=EmployeeID='" + id + "'");
    parent.NeedRefreshPage = this;
}

///审核
var fnAudit = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    var url ="/Extend/AjaxData/DataAction.aspx?entity=employee&action=audit&id="+record.getData(const_entityID);
    YAHOO.util.Connect.asyncRequest('POST', url, { success: function (res) {
            try {
                var str = res.responseText;
                if (str == "0") {
                    // 第二步
                    var list = mDataTable.getRecordSet()._records;
                    dl = [];
                    for (var i = 0; i < list.length; i++) {
                        if (list[i]._oData["iSun_Selected"] == true) {
                            dl.push(list[i]._sId); //获取行ID；
                        }
                    }
                }
                else {
                    alert("员工附加信息删除失败，请手动删除员工附加信息！");
                    return;
                }
            }
            catch (e) {
                alert("删除失败：" + e.Message);
                return;
            }
            finally {
            }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
            return;
        }
    }, null);
}

//删除第一步
var fnCustomDelete = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    var id = record.getData(const_entityID);
    //第一步先删除相关的附属信息,包括工作经历，教育经历，技能信息，工作合同，培训经历，项目经历，薪酬信息，岗位异动信息，离职信息
    YAHOO.util.Connect.asyncRequest('POST', "../EHR/hrAjax.aspx?flag=deleteemployee&id=" + id, {
        success: function (res) {
            try {
                var str = res.responseText;
                if (str == "0") {
                    //第二步
                    var list = mDataTable.getRecordSet()._records;
                    dl = [];
                    for (var i = 0; i < list.length; i++) {
                        if (list[i]._oData["iSun_Selected"] == true) {
                            dl.push(list[i]._sId); //获取行ID；
                        }
                    }
                    SaveUrl = "../Extend/AjaxData/DataSave.aspx?r=" + Math.random() + "&action=delete&entity=" + const_EditEntity + "&id=" + id;
                    YAHOO.example.container.dialog3.show();
                }
                else {
                    alert("员工附加信息删除失败，请手动删除员工附加信息！");
                    return;
                }
            }
            catch (e) {
                alert("删除失败：" + e.Message);
                return;
            }
            finally {
            }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
            return;
        }
    }, null);
}

//附属信息
var fnFuShuXinXi = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    //获取功能ID
    var url = encodeURI("../Extend/AjaxData/jsonlist.aspx?entity=SysFunction&condition=Name='附属信息'");
    $.get(url, function (d, s) {
        var list = eval("(" + d + ")");
        if (list.total > 0) {
            for (var o in list.rows) {
                var functionId = list.rows[o].FunctionId;
                if (typeof (functionId) != "undefined") {
                    var pagetitle = "员工附属信息—" + record.getData("CName");
                    parent.addTabs(pagetitle, "../EHR/onetomore.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&id=" + record.getData(const_entityID) + "&functionid=" + functionId);
                    parent.NeedRefreshPage = this;
                    break;
                }
            }
        }
    });
}

//离职
var fnLiZhi = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    PersonnelAffairs("3", "离职");
}

//转正
var fnZhuanZheng = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    //先验证是不是试用员工
    if (record.getData("EmployeeType") == "正式") {
        alert("该员工为正式员工，不需要转正！");
        return;
    }
    PersonnelAffairs("8", "员工转正");
}

//调岗
var fnDiaoGang = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    document.getElementById("dialog1_h").innerHTML = "人事事务—调岗";
    var id = record.getData(const_entityID);
    var deptId = _key;
    var deptName = _Caption;
    var postName = record.getData("PostName");
    var empCode = record.getData("EmployeeCode");
    var empName = record.getData("CName");
    var postRank = record.getData("PostLevel");
    const_EditEntity = 'hrEmployeePositions';
    document.getElementById("EditUIWindow").src = "../Extend/AutoLoadForm.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&empId=" + id + "&postName=" + postName + "&deptName=" + deptName + "&empCode=" + empCode + "&empName=" + empName+"&postRank="+postRank;
    SetDWH(580, 300, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
}

////调岗记录
//var fnDiaoGangJiLu = function () {
//    var recordID = myDataTable.getSelectedRows()[0];
//    record = myDataTable.getRecord(recordID);
//    if (record == null) {
//        alert("请选择一条记录");
//        return;
//    }
//    var deptName = _Caption;
//    var empName = record.getData("CName");
//    document.getElementById("dialog1_h").innerHTML = deptName + empName + "—调岗记录";
//    var id = record.getData(const_entityID);
//    var condition = encodeURI("EmployeeID='" + id + "'");
//    $("#yui-gen0-button").hide();
//    document.getElementById("EditUIWindow").src = "../Extend/YUIDataTableList.aspx?f=a&isShonwBtn=N&functionid=&entity=V_hrEmployeePositions&condition=" + condition;
//    SetDWH(800, 400, YAHOO.example.container.dialog1);
//    YAHOO.example.container.dialog1.show();
//}

//调薪
var fnTiaoXin = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    document.getElementById("dialog1_h").innerHTML = "人事事务—调薪";
    var id = record.getData(const_entityID);
    const_EditEntity = 'hrEmployeeSalary';
    var empCode = record.getData("EmployeeCode");
    var empName = record.getData("CName");
    document.getElementById("EditUIWindow").src = "../Extend/AutoLoadForm.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&empId=" + id + "&empCode=" + empCode + "&empName=" + empName;
    SetDWH(600, 350, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
}

////调薪记录
//var fnTiaoXinJiLu = function () {
//    var recordID = myDataTable.getSelectedRows()[0];
//    record = myDataTable.getRecord(recordID);
//    if (record == null) {
//        alert("请选择一条记录");
//        return;
//    }
//    var deptName = _Caption;
//    var empName = record.getData("CName");
//    document.getElementById("dialog1_h").innerHTML = deptName + empName + "—调薪记录";
//    var id = record.getData(const_entityID);
//    var condition = encodeURI("EmployeeID='" + id + "'");
//    $("#yui-gen0-button").hide();
//    document.getElementById("EditUIWindow").src = "../Extend/YUIDataTableList.aspx?f=a&isShonwBtn=N&functionid=&entity=V_hrEmployeeSalary&condition=" + condition;
//    SetDWH(800, 400, YAHOO.example.container.dialog1);
//    YAHOO.example.container.dialog1.show();
//}

//兼职岗位
var fnPartTimePostion = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    var empName = record.getData("CName");
    //获取功能ID
    var url = encodeURI("../Extend/AjaxData/jsonlist.aspx?entity=SysFunction&condition=Name='兼职岗位'");
    $.get(url, function (d, s) {
        var list = eval("(" + d + ")");
        //debugger
        if (list.total > 0) {
            for (var o in list.rows) {
                var functionId = list.rows[o].FunctionId;
                if (typeof (functionId) != "undefined") {
                    document.getElementById("dialog1_h").innerHTML = empName + "—兼职岗位管理";
                    var id = record.getData(const_entityID);
                    var deptName = _Caption;
                    var postName = record.getData("PostName");
                    var condition = encodeURI("EmployeeID='" + id + "'");
                    $("#yui-gen0-button").hide();
                    document.getElementById("EditUIWindow").src = encodeURI("../Extend/YUIDataTableList.aspx?f=a&isShonwBtn=N&entity=V_hrEmployeePositionsPartTime&condition=" + condition + "&functionid=" + functionId + "&empName=" + empName + "&empId=" + id + "&deptName=" + deptName + "&postName=" + postName);
                    SetDWH(800, 500, YAHOO.example.container.dialog1);
                    YAHOO.example.container.dialog1.show();
                    break;
                }
            }
        }
    });
}

//员工技能
var fnEmpSkill = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    } 
    var empName = record.getData("CName");
    var empID = record.getData(const_entityID);
    var pagetitle = empName + "_技能";
    document.getElementById("dialog1_h").innerHTML = pagetitle;
    var url = "../Extend/YUIDataTableList.aspx?entity=V_hrEmployeeSkills&order=empname,SkillName,[level],SkillLevel&functionID=439DD690-3158-47F4-8FC3-F9659108126B&condition=EmployeeID='" + empID + "'" + "&EmpID=" + empID + "&EmpName=" + empName;
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, url);

}

//初始化
if (typeof ($) != "undefined") {
    $(document).ready(function () {

    });
}

//affairsType-事务类型
var PersonnelAffairs = function (affairsType, affairsName) {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    document.getElementById("dialog1_h").innerHTML = "人事事务—" + affairsName;
    const_EditEntity = 'hrEmployeeAffairs';
    var id = record.getData(const_entityID);
    var empCode = record.getData("EmployeeCode");
    var empName = record.getData("CName");
    document.getElementById("EditUIWindow").src = encodeURI("../Extend/AutoLoadForm.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&affairsType=" + affairsType + "&empId=" + id + "&empCode=" + empCode + "&empName=" + empName);
    SetDWH(550, 320, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
}

////事务记录
//var ShiWuJiLu = function () {
//    var recordID = myDataTable.getSelectedRows()[0];
//    record = myDataTable.getRecord(recordID);
//    if (record == null) {
//        alert("请选择一条记录");
//        return;
//    }
//    var id = record.getData(const_entityID);
//    const_EditEntity = 'hrEmployeeAffairs';
//    document.getElementById("EditUIWindow").src = encodeURI("../Extend/AutoLoadForm.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&id=" + id);
//    SetDWH(550, 320, YAHOO.example.container.dialog1);
//    YAHOO.example.container.dialog1.show();
//}

/*重新加载数据*/
function LoadData() {
    try {
        //    var tempDeptId = getPar(location.href, "functionID");
        //    var deptId = tempDeptId;
        //    var index = tempDeptId.indexOf("#", 0);
        var deptId = _key; //tempDeptId.substring(index + 1);
        const_Condition = "DeptID='" + deptId + "'";
        ReLoadData();
    } catch (e)
    { }
}

////下面的做废
////--------------暂时不用----------------------------------------------
////在职转不在职第一步
//var fnZhuanBuZaiZhi2 = function () {
//    var recordID = myDataTable.getSelectedRows()[0];
//    record = myDataTable.getRecord(recordID);
//    if (record == null) {
//        alert("请选择一条记录");
//        return;
//    }
//    YAHOO.example.container.dialog7.show();
//}
////在职转不在职第二部
//var fnOperationConfig = function () {
//    var recordID = myDataTable.getSelectedRows()[0];
//    record = myDataTable.getRecord(recordID);
//    var id = record.getData(const_entityID)
//    if (id != "") {
//        YAHOO.util.Connect.asyncRequest('POST', "../EHR/hrAjax.aspx?flag=renshishiwu&id=" + id, {
//            success: function (res) {
//                try {
//                    var str = res.responseText;
//                    if (str == "0") {
//                        alert("恭喜，转不在职操作成功!");
//                        LoadData();
//                    }
//                    else {
//                        alert("很遗憾，转不在职操作失败!");
//                    }
//                }
//                catch (e) {
//                }
//                finally {
//                }
//            },
//            failure: function (error) {
//                alert("数据错误：" + error.statusText);
//            }
//        }, null);
//    }
//    YAHOO.example.container.dialog7.hide();
//}
////-------------------------------------------------------------------------------------------------

/////点击异动时
//var fnYiDong = function () {
//    var recordID = myDataTable.getSelectedRows()[0];
//    record = myDataTable.getRecord(recordID);
//    if (record == null) {
//        alert("请选择一条记录");
//        return;
//    }
//    //有ID表示编辑，无ID表示添加
//    var id = record.getData(const_entityID);
//    var tempEmployeeType = record.getData("EmployeeType");
//    var employeeType = 0;
//    if (tempEmployeeType == "正式" || tempEmployeeType == "undefined") {
//        employeeType = 1;
//    }

//    var pagetitle = "员工异动-----" + record.getData("CName");
//    parent.addTabs(pagetitle, "../EHR/ListEmployeeChanges.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&id=" + id + "&employeeType=" + employeeType);
//    parent.NeedRefreshPage = this;

////    document.getElementById("dialog1_h").innerHTML = "员工异动-----" + record.getData("CName");
////    document.getElementById("EditUIWindow").src = "../EHR/ListEmployeeChanges.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&id=" + id + "&employeeType=" + employeeType;
////    SetDWH(800, 500, YAHOO.example.container.dialog1);
////    YAHOO.example.container.dialog1.show();
//}

////点击转正
//var fnZhuanZheng = function () {
//    var recordID = myDataTable.getSelectedRows()[0];
//    record = myDataTable.getRecord(recordID);
//    if (record == null) {
//        alert("请选择一条记录");
//        return;
//    }
//    //有ID表示编辑，无ID表示添加
//    var id = record.getData(const_entityID);
//    var tempEmployeeType = record.getData("EmployeeType");
//    var employeeType = 0;
//    if (tempEmployeeType == "正式" || tempEmployeeType == "undefined") {
//        employeeType = 1;
//    }
//    if (employeeType == 0) {
//        var condition = encodeURI("EmployeeID='" + id + "' and ChangeType='转正'");
//        var functionID = '17d7f5ca-0df4-4427-898a-593cf927baa2'
//        document.getElementById("dialog1_h").innerHTML = "员工转正-----" + record.getData("CName");
//        document.getElementById("EditUIWindow").src = "../Extend/YUIDataTableList.aspx?f=a&isShonwBtn=N&functionid=" + functionID + "&entity=V_hrEmployeePositive&condition=" + condition + "&id=" + id;
//        SetDWH(800, 450, YAHOO.example.container.dialog1);
//        YAHOO.example.container.dialog1.show();
//    }
//    else {
//        alert("该员工已经是正式员工,不需要转正!");
//    }
//}
function custItemOnClick(event, treeId, treeNode, clickFlag) {
    _treeNode = treeNode;
    //debugger
    const_CustomCondition = "DeptPath like '" + _treeNode.DeptPath + "%'";

    initialRequestUrl = "pageindex=1&entity=" + const_entityName + "&order=" + const_Order + "&r=" + Math.random() + "&zip=94089&results=10&output=json&functionid=" + const_functionId + "&customCondition=" + (const_CustomCondition),
    BindData();
    GetTotal("AjaxData/DataTableJsonList.aspx?onlyTotal=true&" + initialRequestUrl);
}

var fnAuditView = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    const_EditEntity = "hrEmployee";
    var deptId = _key;
    var deptName = record.getData("DeptName");
    var postName = record.getData("PostName");
    var pagetitle = "修改在职员工信息—" + record.getData("CName");
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&action=audit&entity=" + const_EditEntity + "&id=" + record.getData(const_entityID) + "&deptId=" + deptId + "&deptName=" + deptName + "&postName=" + postName + "&type=1"));
    parent.NeedRefreshPage = this;
}